﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;

namespace Puzzles_IQ
{
    class Picture
    {
        private int complexity;
        private Image picture;
        private Image[] imgArray;
        private Size picSize, picBlockSize; //size of whole picture and picture block
        public readonly Size blockSize;      // size of 1 block of grid

        int BlockSide { get; set; }   // height|width of 1 block of grid (square)  

        public Picture(Image pic, Complexity c)
        {
            complexity = (int)c; // default
            // picture and image array
            picture = pic;
            imgArray = new Image[complexity * complexity];
            // size of whole picture and picture block
            picSize = picture.Size;
            picBlockSize.Width = picSize.Width / complexity;
            picBlockSize.Height = picSize.Height / complexity;
            //
            BlockSide = 300 / complexity + 20;
            blockSize.Width = blockSize.Height = this.BlockSide;
        }

        public Image[] SliceImage()
        {
            //slicing Image

            for (int i = 0; i < complexity; i++)
            {
                for (int j = 0; j < complexity; j++)
                {
                    //just index
                    var index = j * complexity + i;
                    //creating Bitmaps
                    imgArray[index] = new Bitmap(BlockSide, BlockSide);
                    //
                    var graphics = Graphics.FromImage(imgArray[index]);
                    graphics.DrawImage(picture, new Rectangle(0, 0, BlockSide, BlockSide),
                    new Rectangle(i * picBlockSize.Width, j * picBlockSize.Height, picBlockSize.Width, picBlockSize.Height), GraphicsUnit.Pixel);
                    graphics.Dispose();
                }
            }

            return imgArray;
        }

        public Image GetSmallPicture(string path)
        {
            // turn to small image
            Image im1 = Image.FromFile(path);
            Graphics gr = Graphics.FromImage(im1);
            gr.DrawImage(im1, new Rectangle(0, 0, 180, 180));
            gr.Dispose();
            return im1;
        }

       

    }
}
